using System;
using System.Globalization;
using System.IO;

namespace Atomic.Vasp.Options
{
	/// <summary>
	/// Methfessel-Paxton smearing (ISMEAR=1,2,... and SIGMA).
	/// http://cms.mpi.univie.ac.at/vasp/guide/node124.html
	/// </summary>
	[Serializable]
	public class MethfesselPaxtonSmearing : VaspOption
	{
		/// <summary>
		/// Methfessel-Paxton smearing of first order and default smearing width (0.2 as of VASP 5.3.3).
		/// </summary>
		public MethfesselPaxtonSmearing()
			: this(1)
		{
		}

		/// <summary>
		/// Methfessel-Paxton smearing of specified order and default smearing width (0.2 as of VASP 5.3.3).
		/// </summary>
		public MethfesselPaxtonSmearing(int order)
			: this(order, null)
		{
		}

		/// <summary>
		/// Methfessel-Paxton smearing of specified order and smearing width.
		/// </summary>
		public MethfesselPaxtonSmearing(int order, double? sigma)
		{
			if (order < 1)
			{
				throw new ArgumentException();
			}

			if (sigma.HasValue && sigma.Value <= 0.0)
			{
				throw new ArgumentException();
			}

			Order = order;
			Sigma = sigma;
		}

		public override void Write(VaspIncar incar, DirectoryInfo directory)
		{
			incar.Add("ISMEAR", Order.ToString(), "Methfessel-Paxton method smearing");

			if (Sigma.HasValue)
			{
				incar.Add("SIGMA", Sigma.Value.ToString(CultureInfo.InvariantCulture), "Smearing width");
			}
		}

		public int Order
		{
			get;
			private set;
		}

		public double? Sigma
		{
			get;
			private set;
		}
	}
}
